package com.tongcheng.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.tongcheng.ResultDate;

import com.tongcheng.commons.Contants;
import com.tongcheng.feign.ActivityseviceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Service
public class Activitysevice implements ActivityseviceFeign  {
    @Autowired(required = false)
    private ActivityseviceFeign activityseviceFeign;

    // 通过feign调用服务模块，如果触发熔断机制，则会调用此注解fallbackMethod定义的方法
    @HystrixCommand(fallbackMethod = "checkError1")
    public ResultDate addActivity(@RequestBody Map map) {
        return activityseviceFeign.addActivity(map);
    }
    @HystrixCommand(fallbackMethod = "checkError2")
    public ResultDate delActivity(Integer activity_id){
        return activityseviceFeign.delActivity(activity_id);
    }
    @HystrixCommand(fallbackMethod = "checkError3")
    public ResultDate updateActivity(@RequestBody Map map){
        return activityseviceFeign.updateActivity(map);
    }
    @HystrixCommand(fallbackMethod = "checkError4")
    public ResultDate queryActivity(Integer activity_id){
        return activityseviceFeign.queryActivity(activity_id);
    }
    @HystrixCommand(fallbackMethod = "checkError5")
    public ResultDate queryAllActivity(){
        return activityseviceFeign.queryAllActivity();
    }

    public ResultDate checkError1(HttpServletRequest request,@RequestBody Map map)throws Exception {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError2(Integer activity_id) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError3(@RequestBody Map map) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError4(Integer activity_id) {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
    public ResultDate checkError5() {
        ResultDate resultDate=new ResultDate();
        resultDate.setCode(Contants.FAILURE);
        resultDate.setMsg("系统异常");
        return resultDate;
    }
}
